<template>
  <view>
    <view class="goods_list">
      <view v-for="(item,index) in goods_list" :key="index" @click="gotoDetail(item)">
        <my-goods :goods="item"></my-goods>
      </view>
  </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        queryObj:{
          query:'',
          cid:'',
          pagenum:1,
          pagesize:10
        },
        goods_list:[],
        total:0,
         isLoadding:false
      };
    },
    onLoad(options){
        this.queryObj.query=options.query||''
        this.queryObj.cid=options.cid||''
        
        this.getGoodsList()
    },
    methods:{
      
      
     async getGoodsList(cb){
       //开启节流阀
      this.isLoadding=true
        const {data:res} =await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
        this.total=res.message.total
        this.goods_list=[...this.goods_list,...res.message.goods]
        
        cb&&cb()
        //关闭节流阀
        this.isLoadding=false
      },
      gotoDetail(item){
        uni.navigateTo({
          url:`/subpck/goods_detail/goods_detail?goods_id=${item.goods_id}`
        })
      }
    },
     onReachBottom (){
       if(this.queryObj.pagenum*this.queryObj.pagesize>=this.total)return uni.$showMessage('数据加载完毕!')
       if(this.isLoadding)return 
       
       this.queryObj.pagenum+=1
       this.getGoodsList()
     },
     onPullDownRefresh(){
       //重置关键数据u
       this.queryObj.pagenum=1
       this.total=0
       this.isLoadding=false
       this.goods_list=[]
       
       //重发请求
       this.getGoodsList(()=>uni.stopPullDownRefresh())
       
       
      
     }
   
  }
</script>

<style lang="scss">


</style>
